<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>可选链操作符</title>
</head>
<body>
<script>
    // ?. -- 对象类型的参数深度比较深的时候使用

    function fun(data) {
        // const dbHost=data?.db?.host
        // console.log(dbHost)
        if (data?.db?.host) {// 等于  data && data.db && data.db.host
            console.log(data.db.host + ':' + data.db.post + '?username=' + data.user.username + 'password=' + data.user.password)
        }else {
            console.log(404)
        }
    }

    fun({
        db: {
            host: '127.0.0.1',
            post: 9000
        },
        user: {
            username: 'admin',
            password: 'admin'
        }
    })

</script>
</body>
</html>